package cn.edu.scau.cmi.huxiantao.composite.consistent;

import java.util.HashSet;
import java.util.Set;


public class ConsistentOrganization implements ConsistentComponent {

	private Set<ConsistentComponent> children;
	private String name;
	
	public ConsistentOrganization(String name) {
		this.name=name;
		children=new HashSet<ConsistentComponent>();
	}
	
	@Override
	public String doSomething() {
		String result="一致性组织:"+name+"{\n";
		for(ConsistentComponent component:children) {
			result+=component.doSomething();
		}
		result+="}\n";
		return result;
	}

	@Override
	public void addChild(ConsistentComponent child) {
		this.children.add(child);
	}

	@Override
	public void deleteChild(ConsistentComponent child) {
		this.children.remove(child);
	}

	@Override
	public Set<ConsistentComponent> getChildren() {
		return this.children;
	}

	@Override
	public void updateChildren(Set<ConsistentComponent> children) {
		this.children=children;
	}

	@Override
	public String getName() {
		return this.name;
	}
}
